<fieldset>
	<legend>
		Teilnehmer <a title="Listenansicht"
			href="<?php echo base_url('index.php/training/details/'.$training->id.'?display=table');?>"><i
			style="margin-top: 8px;" class="icon-list"></i>
		</a> <a title="Blockansicht"
			href="<?php echo base_url('index.php/training/details/'.$training->id.'?display=box');?>"><i
			style="margin-top: 8px;" class="icon-th"></i>
		</a>
	</legend>

	<!-- Are there any participants enlisted?
         If so, here we go!
    -->
  
	<?php 
        if(isset($participants)): ?>

	<!-- Check for desired view style.
             If either <<box>> or nothing is selected, continue here.
        -->
	<?php if($display == 'box' OR !$display): ?>

	<!-- Iterate trough participants -->
	<?php foreach($participants as $participant): ?>

	<!-- Output information -->
	<div
		class="profilebox
	<?php
		echo (!$training->place_exists() OR $participant->contactdata()->place()->city === $training->place()->city) 
				? ('tmt_gradient') : 
					('gradient_warning') 
	?>">
	<?php 
    // Did the guy accept the appointment?
        $ico = '';
    if(property_exists($participant, 'confirmation')){
        if ($participant->confirmation === 0)
            $ico = 'cross';
        elseif ($participant->confirmation === 1)
            $ico = 'tick';
        elseif ($participant->confirmation === 2)
            $ico = 'help'; 
        echo '<span ';
        if(property_exists($participant, 'confirmed_at') AND !is_null($participant->confirmed_at))
        echo 'rel="tooltip" title="Anfrage beantwortet: '.date("d.m.y. H:i", strtotime($participant->confirmed_at)).'"';
        
        echo 'class="ic-' . $ico . '" style="float:right;"></span>';
    }
	?>
	
	<?php echo $participant->contactdata()->forename .','. $participant->contactdata()->surname; ?>
		<br>
		<p>
			<?php echo mailto($participant->contactdata()->email);?>
		</p>
		<p>
			<?php echo ($participant->contactdata()->phone != NULL) ? ('Telefon: '.$participant->contactdata()->phone) : 'Telefon: -';?>
		</p>

		<!-- DOOF -->
		<?php foreach ($participant->team() as $team) {
			echo '<p>Team: '. $team->name . '</p>';
		}
		?>

		<p>
			Standort:
			<?php echo $participant->contactdata()->place()->city ?>
		</p>
	</div>
	<?php endforeach; ?>

	<!-- Check for desired view style.
             If <<table>> is selected, continue here.
        -->
	<?php elseif($display == 'table'): ?>
	<?php $i=1;?>
	<table class="table table-condensed">
		<tr>
			<th>#</th>
			<th>Name</th>
			<th>Vorname</th>
			<th>E-Mail</th>
			<th>Telefon</th>
			<th>Team</th>
			<th>Standort</th>
		</tr>

		<!-- Iterate trough participants -->
		<?php foreach($participants as $participant): ?>

		<!-- Output participant information -->
		<tr
		<?php echo (!$training->place_exists() OR $participant->contactdata()->place()->city === $training->place()->city) ? ('') : 'class="color_warning"' ?>>
			<td><?php echo $i++;?>
			</td>
			<td><?php echo $participant->contactdata()->forename; ?>
			</td>
			<td><?php echo $participant->contactdata()->surname; ?>
			</td>
			<td><?php echo mailto($participant->contactdata()->email); ?>
			</td>
			<td><?php echo ($participant->contactdata()->phone != NULL) ? ($participant->contactdata()->phone) : '-'; ?>
			</td>
			<td>
				<!-- DOOF --> <?php foreach ($participant->team() as $team) {
					echo $team->name;
				}
				?>
			</td>
			<td><?php echo $participant->contactdata()->place()->city; ?>
			</td>
                        
                        <?php 
                        // Did the guy accept the appointment?
                        $ico = '';
                        if(property_exists($participant, 'confirmation')){
                            echo '<td>';
                            if ($participant->confirmation === 0)
                                $ico = 'cross';
                            elseif ($participant->confirmation === 1)
                                $ico = 'tick';
                            elseif ($participant->confirmation === 2)
                                $ico = 'help'; 
                            echo '<span class="ic-' . $ico .'"></span>';
                            
                            echo '</td>';
                        }
                            ?>
		</tr>
		<?php endforeach; ?>
	</table>

	<!-- End of view style condition -->
	<?php endif; ?>

	<!-- Are there any participants enlisted?
         If not, throw an error!
    -->
	<?php else: ?>
	<div class="alert alert-danger">Achtung es konnten keine Mitarbeiter
		geladen werden!</div>

	<!-- End of participant condition -->
	<?php endif; ?>

</fieldset>
